from flask import Flask, jsonify
from flask_cors import CORS
from flask_jwt_extended import JWTManager
from datetime import datetime, timedelta

def init_middleware(app: Flask):
    # 配置 JWT
    app.config['JWT_SECRET_KEY'] = 'your_jwt_secret_key'  # 替换为你的密钥
    app.config['JWT_ACCESS_TOKEN_EXPIRES'] = timedelta(hours=24)  # 设置 token 有效期
    CORS(app)
    jwt =JWTManager(app)

    @jwt.expired_token_loader
    def my_expired_token_callback(jwt_header, jwt_payload):
        return jsonify({"status":"failed","message":"token已过期","data":None}), 401
